using System.Collections.Generic;
using System.Linq;
using Domain.Model.Banks;
using Infrastructure.Data;

namespace Application.Services.BankingManagement
{
    public class BankingManagementService : IBankingManagementService
    {
        private readonly IMainModuleUnitOfWork _unitOfWork;

        public BankingManagementService(IMainModuleUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        #region Implementation of IBankingManagementService

        public List<Bank> GetAllBanks()
        {
            return _unitOfWork.Banks.ToList();
        }

        public Bank FindBankByBIC(string bankBIC)
        {
            return _unitOfWork.Banks.Find(bankBIC);
        }

        public bool SaveBank(Bank bank)
        {
            // Add bank to Banks repository
            _unitOfWork.Banks.Add(bank);

            // Commit changes
            return _unitOfWork.SaveChanges() == 1 ? true : false;
        }

        public bool DeleteBank(Bank bank)
        {
            // Remove bank from Banks repository
            _unitOfWork.Banks.Remove(bank);

            // Commit changes
            return _unitOfWork.SaveChanges() == 1 ? true : false;
        }

        #endregion
    }
}